package com.itheima.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class ProxyTest {
    public static void main(String[] args) {
        Car car = new CarImpl();

        Car proxyCar = (Car) Proxy.newProxyInstance(ProxyTest.class.getClassLoader(), car.getClass().getInterfaces(), new InvocationHandler() {
            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                System.out.println("方法执行前");
                Object invoke = method.invoke(car, args);
                System.out.println("方法执行后");
                return invoke;
            }
        });


        /*car.save();
        car.delete(1);
        car.update();
        String str = car.find();
        System.out.println(str);*/
        proxyCar.save();
        proxyCar.delete(1);
        proxyCar.update();
        String str = proxyCar.find();
        System.out.println(str);
    }
}
